﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebServiceKFC.Model;

namespace WebServiceKFC.MonAnF
{
    public class MonAnFactoryDTO
    {
        private static List<MonAnDTO> sampleMonAnDons = new List<MonAnDTO>();

        public MonAnFactoryDTO()
        {
            InitListOfSampleMonAnDon();
        }

        public void InitListOfSampleMonAnDon()
        {
            sampleMonAnDons = new List<MonAnDTO>();
            sampleMonAnDons.Add(new GaRanTruyenThongDTO());
            sampleMonAnDons.Add(new ThucAnNheDTO());
            sampleMonAnDons.Add(new ThucAnPhuDTO());
            sampleMonAnDons.Add(new MonTrangMiengGiaiKhatDTO());
            sampleMonAnDons.Add(new PhanAnComboDTO());
            sampleMonAnDons.Add(new PhanAnTreEmDTO());
        }

        public static void add(MonAnDTO ma)
        {
            for (int i = 0; i < sampleMonAnDons.Count; i++)
            {
                if (ma.LayTenLoaiDoiTuong() == sampleMonAnDons[i].LayTenLoaiDoiTuong())
                    return;
            }

            sampleMonAnDons.Add(ma);
        }

        //public MonAnDTO GetMonAn(int idx)
        //{
        //    if (idx >= 0 && idx < sampleMonAnDons.Count)
        //    {
        //        return sampleMonAnDons[idx].Clone();
        //    }
        //    return null;
        //}

        public static MonAnDTO Produce(string strMonAnType)
        {
            for (int i = 0; i < sampleMonAnDons.Count; i++)
            {
                if (sampleMonAnDons[i].LayTenLoaiDoiTuong() == strMonAnType)
                    return sampleMonAnDons[i].Clone();
            }
            return null;
        }

        public  List<MonAnDTO> LayDSMonAn()
        {
            List<MonAnDTO> list = new List<MonAnDTO>();

            DatabaseKFCEntities db = new DatabaseKFCEntities();
            foreach (var i in db.MonAns)
            {
                MonAnDTO mo_an = Produce(i.LoaiDoiTuong);
                mo_an.SetInforFrom(i);
                
                list.Add(mo_an);
            }
            return list;
        }
    }
}